package fr.mywiki.view.web.struts.form.file;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import org.apache.struts.action.ActionForm;
import org.apache.struts.upload.FormFile;

import fr.mywiki.business.file.FileManager;
import fr.mywiki.business.resources.ResourceManager;

/**
 * Action form dedicated to the file management.
 */
public class ManageFileForm extends ActionForm {
	private static final long serialVersionUID = 1L;

	/** The container of a new file */
	protected FormFile formFile;

	/** A message to display, relative to the file management */
	private String fileMessage;

	/** The list of files to display */
	private List filesList;

	/** The identifier of the file which has been selected in the popup */
	private String selectedFileId;
	
	/** The name of the file to upload */
	private String fileName;

	/**
	 * Initializes the list of files with all the available files
	 */
	public void initFilesList() {
		try {
			filesList = FileManager.getAllFilesLight();
		} catch (Exception e) {
			filesList = new ArrayList();
			fileMessage = ResourceManager.getError("file.list.failedLoad", Locale
					.getDefault());
		}
	}
	
	public FormFile getFormFile() {
		return formFile;
	}

	public void setFormFile(FormFile formFile) {
		this.formFile = formFile;
	}

	public String getFileMessage() {
		return fileMessage;
	}

	public void setFileMessage(String message) {
		this.fileMessage = message;
	}

	public List getFilesList() {
		return filesList;
	}

	public void setFilesList(List filesList) {
		this.filesList = filesList;
	}

	public String getSelectedFileId() {
		return selectedFileId;
	}

	public void setSelectedFileId(String selectedFileId) {
		this.selectedFileId = selectedFileId;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
}